package com.fudan.es.aggs.request.handler.dimension;

import org.elasticsearch.search.aggregations.AggregationBuilder;

import com.fudan.es.aggs.DimensionParser.DimensionType;
import com.fudan.es.aggs.request.handler.BaseHandler;
import com.fudan.es.entity.DimensionPack;
import com.fudan.framework.utils.SpringUtils;

public abstract class DimensionHandler extends BaseHandler{

	abstract public AggregationBuilder handle(DimensionPack dimension);

	public static DimensionHandler buildHandler(DimensionType type) {
		switch (type) {
		case TERMS:
			return get(TermsHandler.class);
		case DATE:
			return get(DateHandler.class);
		default:
			return null;
		}
	}

	public static <T> T get(Class<T> clz) {
		return SpringUtils.getBean(clz);
	}
}
